package com.itheima.health.controller.admin;

import com.itheima.health.common.MessageConst;
import com.itheima.health.common.RedisConst;
import com.itheima.health.pojo.entity.OrderSetting;
import com.itheima.health.pojo.result.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("ordersetting")
public class OrderSettingController {

   /*
   *获取上传到前端的excel表文件
   *读取表中数据
   */

       //获取上传到前端后台的文件
    @Autowired
    private OrderSettingService orderSettingService;
    @RequestMapping("/upload")
    public Result getExcelFile(MultipartFile excelFile) {
         log.info("上传文件:{}",excelFile.getOriginalFilename());
         orderSettingService.insertOrderSettingFile(excelFile);
         return new Result(true,MessageConst.IMPORT_ORDERSETTING_SUCCESS);
    }


    @RequestMapping("getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String year,String month) {
        log.info("获取预约设置数据:{}",year+"-"+month);
        List<OrderSetting> list=orderSettingService.getOrderSettingByMonth(year,month);
        return new Result(true,MessageConst.GET_ORDERSETTING_SUCCESS,list);
    }

    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {

        log.info("预约设置数据:日期={}，数量={}",orderSetting.getDate(),orderSetting.getNumber());
         orderSettingService.editNumberByDate(orderSetting);
        return new Result(true,MessageConst.ORDERSETTING_SUCCESS);
    }
}
